package TCP;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package test
 * @date 2024/4/10 上午10:04
 */
public class Day10_Client_Thread {
    public static void main(String[] args) {


        try {
            InetAddress inetAddress = InetAddress.getLocalHost();
            Socket socket = new Socket(inetAddress, 8888);
            System.out.println("服务器连接成功");
            Scanner scanner = new Scanner(System.in);
            Thread thread = new Thread(new Day10_Client_Thread_outclass(socket));
            thread.start();
            OutputStream outputStream = socket.getOutputStream();
            PrintWriter pw = new PrintWriter(outputStream, true);
            while (true) {
                System.out.println("请输入要发送的内容");
                String word = scanner.nextLine();
                if ("bye".equals(word)) {
                    pw.println(word);
                    break;
                } else {
                    pw.println(word);
                }
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }
}
